libostree: Move sysroot initialization API here
authorColin Walters <walters@verbum.org>
Sun, 15 Sep 2013 19:16:56 +0000 (15:16 -0400)
committerColin Walters <walters@verbum.org>
Sun, 15 Sep 2013 19:16:56 +0000 (15:16 -0400)
src/libostree/ostree-sysroot.c
src/libostree/ostree-sysroot.h
src/ostree/ot-admin-builtin-init-fs.c
src/ostree/ot-admin-builtin-os-init.c
src/ostree/ot-admin-functions.c

index 4fa27af04ae98f999ba24ef6c1f971419ebb50f4..3f1fa37645225b1d4254bc0a7ac6c54237fbd392 100644 (file)
@@ -174,3 +174,52 @@ ostree_sysroot_get_path (OstreeSysroot  *self)
 {
   return self->path;
 }
+
+/**
+ * ostree_sysroot_ensure_initialized:
+ * @self:
+ *
+ * Ensure that @self is set up as a valid rootfs, by creating
+ * /ostree/repo, among other things.
+ */
+gboolean
+ostree_sysroot_ensure_initialized (OstreeSysroot  *self,
+                                   GCancellable   *cancellable,
+                                   GError        **error)
+{
+  gboolean ret = FALSE;
+  gs_unref_object GFile *dir = NULL;
+  gs_unref_object GFile *ostree_dir = NULL;
+
+  ostree_dir = g_file_get_child (self->path, "ostree");
+
+  g_clear_object (&dir);
+  dir = g_file_get_child (ostree_dir, "repo");
+  if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
+    goto out;
+
+  g_clear_object (&dir);
+  dir = g_file_get_child (ostree_dir, "deploy");
+  if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
+    goto out;
+
+  g_clear_object (&dir);
+  dir = ot_gfile_get_child_build_path (ostree_dir, "repo", "objects", NULL);
+  if (!g_file_query_exists (dir, NULL))
+    {
+      gs_free char *opt_repo_arg = g_strdup_printf ("--repo=%s/repo",
+                                                      gs_file_get_path_cached (ostree_dir));
+
+      if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
+                                          cancellable, error,
+                                          "ostree", opt_repo_arg, "init", NULL))
+        {
+          g_prefix_error (error, "Failed to initialize repository: ");
+          goto out;
+        }
+    }
+
+  ret = TRUE;
+ out:
+  return ret;
+}
index b983383bbd60c85937d77ba56c125b85ee0b7832..490d5d2c1ab23f759ac1d4a663da94e0589013ff 100644 (file)
@@ -38,5 +38,9 @@ OstreeSysroot* ostree_sysroot_new_default (void);
 
 GFile *ostree_sysroot_get_path (OstreeSysroot *self);
 
+gboolean ostree_sysroot_ensure_initialized (OstreeSysroot  *self,
+                                            GCancellable   *cancellable,
+                                            GError        **error);
+
 G_END_DECLS
 
index 78872b77160c7e5d388d470725db6f7076ebfbf2..01114c5b27a3168f6dc21b4b8229c97e18f303d6 100644 (file)
@@ -40,6 +40,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancel
   gboolean ret = FALSE;
   gs_unref_object GFile *dir = NULL;
   gs_unref_object GFile *child = NULL;
+  gs_unref_object OstreeSysroot *target_sysroot = NULL;
   guint i;
   const char *normal_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"};
 
@@ -56,6 +57,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancel
     }
 
   dir = g_file_new_for_path (argv[1]);
+  target_sysroot = ostree_sysroot_new (dir);
 
   for (i = 0; i < G_N_ELEMENTS(normal_toplevels); i++)
     {
@@ -75,7 +77,7 @@ ot_admin_builtin_init_fs (int argc, char **argv, OstreeSysroot *sysroot, GCancel
     goto out;
   g_clear_object (&child);
 
-  if (!ot_admin_ensure_initialized (dir, cancellable, error))
+  if (!ostree_sysroot_ensure_initialized (target_sysroot, cancellable, error))
     goto out;
 
   ret = TRUE;
index 414662a4ec951a915944cb5511e069c4b9b598f1..e15150603dbfc3d21d40693ca9ab656e49bd20db 100644 (file)
@@ -48,7 +48,7 @@ ot_admin_builtin_os_init (int argc, char **argv, OstreeSysroot *sysroot, GCancel
   if (!g_option_context_parse (context, &argc, &argv, error))
     goto out;
 
-  if (!ot_admin_ensure_initialized (ostree_sysroot_get_path (sysroot), cancellable, error))
+  if (!ostree_sysroot_ensure_initialized (sysroot, cancellable, error))
     goto out;
 
   if (argc < 2)
index 770857ad7c977da618209a97f76411ee33e53e17..2cef98cbfb93831a9ab3888db0a3df992da9b8aa 100644 (file)
@@ -92,48 +92,6 @@ match_info_cleanup (void *loc)
   if (*match) g_match_info_unref (*match);
 }
 
-gboolean
-ot_admin_ensure_initialized (GFile         *sysroot,
-                             GCancellable  *cancellable,
-                             GError       **error)
-{
-  gboolean ret = FALSE;
-  gs_unref_object GFile *dir = NULL;
-  gs_unref_object GFile *ostree_dir = NULL;
-
-  ostree_dir = g_file_get_child (sysroot, "ostree");
-
-  g_clear_object (&dir);
-  dir = g_file_get_child (ostree_dir, "repo");
-  if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
-    goto out;
-
-  g_clear_object (&dir);
-  dir = g_file_get_child (ostree_dir, "deploy");
-  if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
-    goto out;
-
-  g_clear_object (&dir);
-  dir = ot_gfile_get_child_build_path (ostree_dir, "repo", "objects", NULL);
-  if (!g_file_query_exists (dir, NULL))
-    {
-      gs_free char *opt_repo_arg = g_strdup_printf ("--repo=%s/repo",
-                                                      gs_file_get_path_cached (ostree_dir));
-
-      if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
-                                          cancellable, error,
-                                          "ostree", opt_repo_arg, "init", NULL))
-        {
-          g_prefix_error (error, "Failed to initialize repository: ");
-          goto out;
-        }
-    }
-
-  ret = TRUE;
- out:
-  return ret;
-}
-
 gboolean
 ot_admin_check_os (GFile         *sysroot, 
                    const char    *osname,